import 'package:flutter/material.dart';
import 'package:my_app_01/pages/cockpit/index.dart';
import 'package:my_app_01/pages/me/index.dart';
import 'package:my_app_01/pages/routes.dart';

import 'home/index.dart';
import 'menu/index.dart';

class AppPage extends StatefulWidget {
  @override
  State<StatefulWidget> createState() {
    return _AppPage();
  }
}

class _AppPage extends State<AppPage> {
  @override
  Widget build(BuildContext context) {
    return DefaultTabController(
      length: 4,
      child: Scaffold(
        drawer: Drawer(
          child: ListView(
            padding: const EdgeInsets.all(0),
            children: [
              const UserAccountsDrawerHeader(
                currentAccountPictureSize: Size.square(55),
                accountName: Text(
                  "hoongs",
                  style: TextStyle(color: Colors.black, fontSize: 26),
                  strutStyle: StrutStyle(),
                ),
                accountEmail: Text(
                  "hoongs0219@gmail.com",
                  style: TextStyle(color: Colors.black54, fontSize: 20),
                ),
                currentAccountPicture: CircleAvatar(
                  backgroundImage:
                      NetworkImage("https://cdn.uviewui.com/uview/album/1.jpg"),
                ),
                // 美化当前控件
                decoration: BoxDecoration(
                  image: DecorationImage(
                      fit: BoxFit.cover,
                      image: NetworkImage(
                          "https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fsafe-img.xhscdn.com%2Fbw1%2F0dbf177b-92e3-4fdf-ab8c-f9c2832d2942%3FimageView2%2F2%2Fw%2F1080%2Fformat%2Fjpg&refer=http%3A%2F%2Fsafe-img.xhscdn.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=auto?sec=1681456589&t=102977fb12c2926a5b4a495347336eba")),
                ),
              ),
              const ListTile(
                  title: Text("个人中心"), trailing: Icon(Icons.account_circle)),
              const ListTile(
                  title: Text("通讯录"), trailing: Icon(Icons.settings)),
              const ListTile(title: Text("常见问题"), trailing: Icon(Icons.help)),
              const ListTile(title: Text("操作指南"), trailing: Icon(Icons.source)),
              const ListTile(title: Text("密码修改"), trailing: Icon(Icons.key)),
              const Divider(),
              ListTile(
                title: const Text("退出登录"),
                trailing: const Icon(Icons.power_settings_new),
                onTap: () {
                  Navigator.of(context).pushNamedAndRemoveUntil(
                      RouterTable.loginPath, (Route route) => false);
                },
              ),
            ],
          ),
        ),
        body: TabBarView(
          children: [
            const HomePage(),
            const CockpitPage(),
            MenuPage(),
            MePage(),
          ],
        ),
        bottomNavigationBar: SafeArea(
          child: Container(
            decoration: const BoxDecoration(
              color: Color.fromRGBO(252, 252, 252, 50),
              border: Border(
                top: BorderSide(
                  //                    <--- top side
                  color: Colors.black12,
                  width: 1,
                ),
              ),
            ),
            height: 60,
            child: const TabBar(
              labelStyle: TextStyle(height: 0, fontSize: 10),
              indicator: BoxDecoration(),
              tabs: [
                Tab(
                    icon: Icon(
                      Icons.home,
                      size: 20,
                    ),
                    text: "主页",
                    iconMargin: EdgeInsets.fromLTRB(0, 5, 0, 5)),
                Tab(
                    icon: Icon(
                      Icons.storage,
                      size: 20,
                    ),
                    text: "驾驶舱",
                    iconMargin: EdgeInsets.fromLTRB(0, 5, 0, 5)),
                Tab(
                    icon: Icon(
                      Icons.dashboard,
                      size: 20,
                    ),
                    text: "工作台",
                    iconMargin: EdgeInsets.fromLTRB(0, 5, 0, 5)),
                Tab(
                    icon: Icon(
                      Icons.person,
                      size: 20,
                    ),
                    text: "我的",
                    iconMargin: EdgeInsets.fromLTRB(0, 5, 0, 5))
              ],
            ),
          ),
        ),
      ),
    );
  }

  @override
  void initState() {
    super.initState();
  }
}
